public class IocNewComputers {
    //制作一个电脑
    public static void main(String[] args) {
        Cpu cpu=new Cpu("AMD的锐龙Ryzen系列");
        Hardware hardware=new Hardware(cpu);
        Configuration configuration=new Configuration(hardware);
        Computer computer=new Computer(configuration);

        computer.run();
    }
    //电脑对象
    static class Computer{
        private  Configuration configuration;
        public Computer(Configuration configuration){
            this.configuration=configuration;
        }
        public void run(){
            //依赖配置
            configuration.init();
        }
    }
    //配置对象
    static class Configuration{
        private Hardware hardware;
        public Configuration (Hardware hardware){
            this.hardware=hardware;
        }
        public void init(){
            //依赖硬件
            hardware.init();
        }
    }
    //配置硬件
    static class Hardware{
        private Cpu cpu;
        public Hardware (Cpu cpu){
            this.cpu=cpu;
        }
        public void init(){
            //依赖CPU
            cpu.init();
        }
    }
    //配置CPU
    static class Cpu{
        private String model;
        public Cpu(String model){
            this.model=model;
        }
        public void init(){
            System.out.println("CPU型号——>"+model);
        }
    }
}
